import { message } from 'ant-design-vue';

export function useData() {
  const data = ref<VAPI.DataItem[]>([]);
  const loading = ref(false);
  async function getAllData() {
    loading.value = true;
    try {
      const res: VAPI.DataResponse = await getAllRecord();
      if (res) {
        if (res.data.length > 0) {
          data.value = res.data;
        }
        else {
          message.success('数据库中无数据');
        }
      }
    }
    catch (error) {
      message.error('获取数据失败');
    }
    loading.value = false;
  }
  onMounted(() => getAllData());

  return {
    data,
    loading,
    getAllData,
  };
}
